from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-29 14:13:09.014966
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 29, Sep, 2021
Time: 14:13:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4280
Nobs: 429.000 HQIC: -46.9436
Log likelihood: 4753.05 FPE: 2.92793e-21
AIC: -47.2801 Det(Omega_mle): 2.37955e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.423793 0.091555 4.629 0.000
L1.Burgenland 0.105110 0.047450 2.215 0.027
L1.Kärnten -0.113520 0.023804 -4.769 0.000
L1.Niederösterreich 0.153572 0.101810 1.508 0.131
L1.Oberösterreich 0.110778 0.099821 1.110 0.267
L1.Salzburg 0.286171 0.049924 5.732 0.000
L1.Steiermark 0.035595 0.066422 0.536 0.592
L1.Tirol 0.105744 0.052468 2.015 0.044
L1.Vorarlberg -0.101722 0.047081 -2.161 0.031
L1.Wien 0.000746 0.091028 0.008 0.993
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014316 0.209075 0.068 0.945
L1.Burgenland -0.051346 0.108356 -0.474 0.636
L1.Kärnten 0.037480 0.054358 0.689 0.491
L1.Niederösterreich -0.208231 0.232493 -0.896 0.370
L1.Oberösterreich 0.495137 0.227951 2.172 0.030
L1.Salzburg 0.305726 0.114006 2.682 0.007
L1.Steiermark 0.103748 0.151682 0.684 0.494
L1.Tirol 0.313175 0.119815 2.614 0.009
L1.Vorarlberg 0.000524 0.107513 0.005 0.996
L1.Wien 0.001391 0.207871 0.007 0.995
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.241068 0.046119 5.227 0.000
L1.Burgenland 0.092814 0.023902 3.883 0.000
L1.Kärnten -0.001846 0.011991 -0.154 0.878
L1.Niederösterreich 0.212616 0.051285 4.146 0.000
L1.Oberösterreich 0.155401 0.050283 3.091 0.002
L1.Salzburg 0.037175 0.025148 1.478 0.139
L1.Steiermark 0.024523 0.033459 0.733 0.464
L1.Tirol 0.068596 0.026429 2.595 0.009
L1.Vorarlberg 0.059226 0.023716 2.497 0.013
L1.Wien 0.111885 0.045853 2.440 0.015
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186471 0.045312 4.115 0.000
L1.Burgenland 0.046498 0.023484 1.980 0.048
L1.Kärnten -0.006445 0.011781 -0.547 0.584
L1.Niederösterreich 0.141809 0.050387 2.814 0.005
L1.Oberösterreich 0.317966 0.049403 6.436 0.000
L1.Salzburg 0.100639 0.024708 4.073 0.000
L1.Steiermark 0.129168 0.032873 3.929 0.000
L1.Tirol 0.077060 0.025967 2.968 0.003
L1.Vorarlberg 0.055683 0.023301 2.390 0.017
L1.Wien -0.048829 0.045051 -1.084 0.278
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.204447 0.089856 2.275 0.023
L1.Burgenland -0.046180 0.046569 -0.992 0.321
L1.Kärnten -0.033688 0.023362 -1.442 0.149
L1.Niederösterreich 0.119380 0.099920 1.195 0.232
L1.Oberösterreich 0.168668 0.097968 1.722 0.085
L1.Salzburg 0.250256 0.048997 5.108 0.000
L1.Steiermark 0.075541 0.065190 1.159 0.247
L1.Tirol 0.124993 0.051494 2.427 0.015
L1.Vorarlberg 0.114620 0.046207 2.481 0.013
L1.Wien 0.025829 0.089339 0.289 0.772
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.035698 0.069401 0.514 0.607
L1.Burgenland 0.021036 0.035968 0.585 0.559
L1.Kärnten 0.054806 0.018044 3.037 0.002
L1.Niederösterreich 0.207977 0.077174 2.695 0.007
L1.Oberösterreich 0.339108 0.075667 4.482 0.000
L1.Salzburg 0.047482 0.037843 1.255 0.210
L1.Steiermark -0.008361 0.050350 -0.166 0.868
L1.Tirol 0.111280 0.039772 2.798 0.005
L1.Vorarlberg 0.069269 0.035688 1.941 0.052
L1.Wien 0.122908 0.069001 1.781 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195568 0.084830 2.305 0.021
L1.Burgenland 0.015428 0.043964 0.351 0.726
L1.Kärnten -0.057063 0.022055 -2.587 0.010
L1.Niederösterreich -0.122058 0.094331 -1.294 0.196
L1.Oberösterreich 0.193754 0.092488 2.095 0.036
L1.Salzburg 0.034303 0.046257 0.742 0.458
L1.Steiermark 0.287452 0.061543 4.671 0.000
L1.Tirol 0.490373 0.048614 10.087 0.000
L1.Vorarlberg 0.077256 0.043622 1.771 0.077
L1.Wien -0.112154 0.084341 -1.330 0.184
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157899 0.092696 1.703 0.088
L1.Burgenland -0.011224 0.048041 -0.234 0.815
L1.Kärnten 0.063438 0.024100 2.632 0.008
L1.Niederösterreich 0.198258 0.103078 1.923 0.054
L1.Oberösterreich -0.125434 0.101064 -1.241 0.215
L1.Salzburg 0.233582 0.050546 4.621 0.000
L1.Steiermark 0.150141 0.067250 2.233 0.026
L1.Tirol 0.049401 0.053121 0.930 0.352
L1.Vorarlberg 0.129727 0.047667 2.722 0.006
L1.Wien 0.156393 0.092162 1.697 0.090
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.478931 0.050352 9.512 0.000
L1.Burgenland -0.006356 0.026096 -0.244 0.808
L1.Kärnten -0.009462 0.013091 -0.723 0.470
L1.Niederösterreich 0.205986 0.055992 3.679 0.000
L1.Oberösterreich 0.252265 0.054898 4.595 0.000
L1.Salzburg 0.023757 0.027456 0.865 0.387
L1.Steiermark -0.021024 0.036530 -0.576 0.565
L1.Tirol 0.065936 0.028855 2.285 0.022
L1.Vorarlberg 0.060258 0.025893 2.327 0.020
L1.Wien -0.047816 0.050062 -0.955 0.340
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021048 0.080082 0.140129 0.128720 0.045034 0.075046 -0.000771 0.186275
Kärnten 0.021048 1.000000 -0.043651 0.129316 0.048763 0.071460 0.453504 -0.090165 0.089459
Niederösterreich 0.080082 -0.043651 1.000000 0.282564 0.080398 0.267506 0.024648 0.136998 0.259661
Oberösterreich 0.140129 0.129316 0.282564 1.000000 0.176122 0.288489 0.156936 0.101447 0.135808
Salzburg 0.128720 0.048763 0.080398 0.176122 1.000000 0.124232 0.055395 0.107432 0.049967
Steiermark 0.045034 0.071460 0.267506 0.288489 0.124232 1.000000 0.132411 0.091421 -0.015631
Tirol 0.075046 0.453504 0.024648 0.156936 0.055395 0.132411 1.000000 0.046050 0.117585
Vorarlberg -0.000771 -0.090165 0.136998 0.101447 0.107432 0.091421 0.046050 1.000000 -0.047666
Wien 0.186275 0.089459 0.259661 0.135808 0.049967 -0.015631 0.117585 -0.047666 1.000000